package com.googlecode.yoohoo.xmppcore.protocol.stream;

import com.googlecode.yoohoo.xmppcore.protocol.parsing.ProtocolKey;
import com.googlecode.yoohoo.xmppcore.protocol.translation.ITranslator;
import com.googlecode.yoohoo.xmppcore.protocol.translation.IXmlWriter;
import com.googlecode.yoohoo.xmppcore.protocol.translation.XmlWriter;

public class Bind implements ITranslator {
	public static final ProtocolKey PROTOCOL_KEY = new ProtocolKey("bind", "urn:ietf:params:xml:ns:xmpp-bind");
	
	private String resource;
	private String jid;
	
	public String getResource() {
		return resource;
	}
	
	public void setResource(String resource) {
		this.resource = resource;
	}
	
	public String getJid() {
		return jid;
	}

	public void setJid(String jid) {
		this.jid = jid;
	}

	@Override
	public String toXml() {
		IXmlWriter writer = new XmlWriter();
		writer.writeStartElement("bind");
		writer.writeNamespace("urn:ietf:params:xml:ns:xmpp-bind");
		if (resource != null) {
			writer.writeStartElement("resource");
			writer.writeCharacters(resource);
			writer.writeEndElement();
		}
		
		if (jid != null) {
			writer.writeStartElement("jid");
			writer.writeCharacters(jid);
			writer.writeEndElement();
		}
		
		writer.writeEndElement();

		return writer.toXml();
	}

}
